import Vue from 'vue'

Vue.filter('moneyFormat', function(value, point) {
	return Number(value).toFixed(point);
})

Vue.filter("formatMoneyRmbUnit", (value) => {
	if (!value) {
		return "￥0";
	}
	return "￥" + value;
})


Vue.filter("formatMoneyChinese", (value) => {
	if (!value) {
		return "0元";
	}
	return value + "元";
})


Vue.filter('initFormatStr', function(value) {
	if (!value) {
		return '';
	}
	return value;
})

/**
 * 数量超过1万用1W+显示
 */
Vue.filter('numFormat', function(value) {
	value = parseInt(value)
	return value > 10000 ? parseInt((value - value % 1000) / 10000) + '万+' : (value)
})

/**
 * 密文手机号码
 */
Vue.filter('cipherTepl', function(value) {
	if (!value) return ''
	let first = value.slice(0, 3)
	let last = value.slice(7, 11)
	return first + '****' + last
})

Vue.filter('timeFormat', function(value, format) {
	let result = "";
	if (value) {
		value = value.replace(/-/g, '/');
		let date = new Date(value);
		let y = date.getFullYear();
		let m = date.getMonth() + 1;
		let d = date.getDate();
		let h = date.getHours();
		let min = date.getMinutes();
		let s = date.getSeconds();

		if (format == undefined) {
			result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d} ${
		    h < 10 ? "0" + h : h
		  }:${min < 10 ? "0" + min : min}:${s < 10 ? "0" + s : s}`;
		}
		if (format == "yyyy-mm-dd") {
			result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d}`;
		}
		if (format == "yyyy-mm") {
			result = `${y}-${m < 10 ? "0" + m : m}`;
		}
		if (format == "mm-dd") {
			result = ` ${mm < 10 ? "0" + mm : mm}:${ddmin < 10 ? "0" + dd : dd}`;
		}
		if (format == "hh:mm") {
			result = ` ${h < 10 ? "0" + h : h}:${min < 10 ? "0" + min : min}`;
		}
		if (format == "yyyy") {
			result = `${y}`;
		}

		if (format == "yyyy-mm-dd hh:mm") {
			result =
				`${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d} ${h < 10 ? "0" + h : h}:${min < 10 ? "0" + min : min}`;
		}
	}
	return result;
});
